#!/bin/bash

 export HOSTNAME=$(hostname)
 export CDS_DOCKER_IMAGE=ovhcom/cds-engine:latest

docker pull ovhcom/cds-engine:latest

docker-compose up -d cds-db cds-cache elasticsearch dockerhost

docker-compose logs| grep 'database system is ready to accept connections'

docker-compose up cds-db-init

docker-compose up cds-migrate

docker-compose up cds-prepare

docker-compose up -d cds-api

TOKEN_CMD=$(docker logs $(docker-compose ps -q cds-prepare) | grep INIT_TOKEN) && $TOKEN_CMD
chmod +x cdsctl

./cdsctl signup --api-url http://localhost:8081 --email admin@localhost.local --username admin --fullname admin

VERIFY_CMD=$(docker-compose logs cds-api | grep 'cdsctl signup verify' | cut -d '$' -f2 | xargs) && ./$VERIFY_CMD

./cdsctl user me

docker-compose up -d cds-ui cds-cdn cds-hooks cds-elasticsearch cds-hatchery-swarm

# ./cdsctl worker model import https://raw.githubusercontent.com/ovh/cds/master/contrib/worker-models/go-official-1.17.yml

# ./cdsctl template push https://raw.githubusercontent.com/ovh/cds/master/contrib/workflow-templates/demo-workflow-hello-world/demo-workflow-hello-world.yml Workflow template shared.infra/demo-workflow-hello-world has been created Template successfully pushed !

# $ ./cdsctl project create DEMO FirstProject
# $ ./cdsctl template apply DEMO MyFirstWorkflow shared.infra/demo-workflow-hello-world --force --import-push --quiet

# # run CDS Workflow!
# $ ./cdsctl workflow run DEMO MyFirstWorkflow
# Workflow MyFirstWorkflow #1 has been launched
# http://localhost:8080/project/DEMO/workflow/MyFirstWorkflow/run/1
